package com.wc.alorithm_luogu.P2670;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/4/25 15:55
 * @description https://www.luogu.com.cn/problem/P2670
 * 扫雷游戏
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int m = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        char[][] map = new char[m][n];
        String s;
        for (int i = 0; i < m; i++) {
            s = sc.next();
            map[i] = s.toCharArray();
        }

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (map[i][j] == '?') {
                    map[i][j] = '0';
                }

                if (map[i][j] == '*') {
                    paint(map, i, j);
                }
            }
        }

        for (char[] row : map) {
            System.out.println(String.valueOf(row));
        }
    }

    public static void paint(char[][] map, int i, int j) {

        // 左上 到 右上
        int left = Math.max(j - 1, 0);
        int right = Math.min(j + 1, map[0].length - 1);

        // 上面 到 下面
        int up = Math.max(i - 1, 0);
        int down = Math.min(i + 1, map.length - 1);

        for (int k = up; k <= down; k++) {
            for (int l = left; l <= right; l++) {
                if (map[k][l] >= '0' && map[k][l] <= '9') {
                    map[k][l]++;
                }

                if (map[k][l] == '?') {
                    map[k][l] = '1';
                }
            }
        }

    }
}
